package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.User;
import com.itheima.service.UserManageService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/userManage")
public class UserManageController {

  @Reference
private UserManageService userManageService;

  @RequestMapping("/findPage")
  public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
    PageResult page =null;
    try {
      page = userManageService.findPage(queryPageBean);
    }catch (Exception e){
      return null;
    }
    return page;
  }

  @RequestMapping("/findRoleById")
  public Result findRoleById(Integer id){
    try {
      List<Integer> roleIds = userManageService.findRoleById(id);
      return new Result(true, MessageConstant.QUERY_ROLE_SUCCESS,roleIds);
    }catch (Exception e){
      return new Result(false,MessageConstant.QUERY_ROLE_FAIL);
    }
  }


  @RequestMapping("/deleteUser")
  public Result deleteUser(Integer id){
    try {
      userManageService.deleteUser(id);
      return new Result(true, MessageConstant.DELETE_USER_SUCCESS);
    }catch (Exception e){
      return new Result(false,MessageConstant.DELETE_USER_FAIL);
    }
  }



}
